package com.ww.juc.futureandcallable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.extern.slf4j.Slf4j;

public class JoinDemo {
	
	private static Logger log = LoggerFactory.getLogger(GuavaFutureDemo.class);

    public static final int SLEEP_GAP = 500;

    public static String getCurThreadName() {
        return Thread.currentThread().getName();
    }

    static class HotWaterThread extends Thread {

        public HotWaterThread() {
            super("** 烧水-Thread");
        }

        @Override
        public void run() {
            try {
                log.info("洗好水壶");
                log.info("灌上凉水");
                log.info("放在火上");
                Thread.sleep(SLEEP_GAP);
                log.info("水开了");
            } catch (InterruptedException e) {
                log.info("发生异常被中断");
            }
            log.info("运动结束");
        }
    }

    static class WashThread extends Thread {

        public WashThread() {
            super("$$ 清洗-Thread");
        }

        @Override
        public void run() {
            try {
                log.info("洗茶壶");
                log.info("洗茶杯");
                log.info("拿茶叶");
                Thread.sleep(SLEEP_GAP);
                log.info("洗完了");
            } catch (InterruptedException e) {
                log.info("发生异常中断了");
            }
            log.info("运动结束了");
        }
    }

    public static void main(String[] args) {
        Thread hThread = new HotWaterThread();
        Thread wThread = new WashThread();

        hThread.start();
        wThread.start();

        try {
            hThread.join();
            wThread.join();

            Thread.currentThread().setName("主线程");
            log.info("泡茶喝");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info(getCurThreadName() + "运动结束...");
    }
}
